package com.spring.sunflower.dialog

import android.content.Context
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.ToastUtils
import com.lxj.xpopup.core.CenterPopupView
import com.spring.sunflower.R
import kotlinx.android.synthetic.main.custom_bottom_dialog.view.*

/**
 * Created by Kevin on 2021/8/6<br/>
 *
 * Describe:<br/>
 */
class HelpChoiceDialog(
    context: Context,
    var listener: OnDialogSelectListener?
) : CenterPopupView(context) {
    private var llContainer: LinearLayout? = null
    private var tvOK: TextView? = null
    private var tvCancel: TextView? = null
    private var tv: TextView? = null
    private var tvItem1: TextView? = null
    private var tvItem2: TextView? = null
    private var selectIndex = -1
    override fun getImplLayoutId(): Int {
        return R.layout.dialog_help_choice
    }

    override fun onCreate() {
        super.onCreate()
        llContainer = findViewById<LinearLayout>(R.id.llContainer)
        tvOK = findViewById(R.id.tvOK)
        tvCancel = findViewById(R.id.tvCancel)
        tv = findViewById(R.id.tv)
        tvItem1 = findViewById<TextView>(R.id.tvItem1)
        tvItem2 = findViewById<TextView>(R.id.tvItem2)
        xListener?.onCreateView()
        tvOK?.setOnClickListener {
            if (selectIndex == -1) {
                ToastUtils.showShort("请选择你的操作")
                return@setOnClickListener
            }
            listener?.onClickOK(selectIndex)
            dismiss()
            selectIndex = -1
        }
        tvCancel?.setOnClickListener { dismiss() }
        tvItem1?.setOnClickListener {
            tvItem1?.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary))
            tvItem2?.setTextColor(ContextCompat.getColor(context, R.color.black_1))
            selectIndex = 0
        }
        tvItem2?.setOnClickListener {
            tvItem1?.setTextColor(ContextCompat.getColor(context, R.color.black_1))
            tvItem2?.setTextColor(ContextCompat.getColor(context, R.color.colorPrimary))
            selectIndex = 1
        }

    }

    fun getContainer(): LinearLayout {
        return llContainer!!
    }

    private var xListener: OnCreateViewListener? = null
    fun setOnCreateViewListener(l: OnCreateViewListener) {
        xListener = l
    }

    fun interface OnCreateViewListener {
        fun onCreateView()
    }

    fun setOKText(str: String) {
        if (str.isNullOrEmpty()) return
        tvOK?.text = str
    }

    fun setCancelText(str: String) {
        if (str.isNullOrEmpty()) return
        tvCancel?.text = str
    }

    fun setHeadTitle(str: String) {
        if (str.isNullOrEmpty()) return
        tv?.text = str
    }

}